# -*- coding: utf-8 -*-
"""
 Created by wq.wang on 2017/12/21
"""
import logging
import ujson

from django.http import HttpRequest

from wserver.base.wapi import WApi, CTYPE_JSON

_logger = logging.getLogger(__name__)


class DjangoWApi(WApi):
    """

    """

    def parse_request(self, request: HttpRequest, *args, **kwargs):

        kwargs.update({k: request.GET[k] for k in request.GET})
        kwargs.update({k: request.POST[k] for k in request.POST})
        if request.content_type in self.consumers:
            if request.content_type == CTYPE_JSON:
                if request.body:
                    kwargs.update(ujson.loads(request.body))
        return kwargs
